﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;

namespace Fengsoft.AIBlog.Web.Code
{
    public static class CookieHelper
    {
        public static string CultureName
        {
            get
            {
                return GetCookieValue("CultureName");
            }
            set
            {
                SetCookieValue("CultureName",value);
            }
        }
        public static string Layout
        {
            get
            {
                return GetCookieValue("Layout");
            }
            set
            {
                SetCookieValue("Layout",value);
            }
        }
        public static string MvcTheme
        {
            get
            {
                string result=GetCookieValue("MvcTheme");
                if (string.IsNullOrEmpty(result))
                {
                    result=ConfigurationManager.AppSettings["MvcTheme"];
                }
                return result;
            }
            set
            {
                SetCookieValue("MvcTheme",value);
            }
        }
        private static string GetCookieValue(string name)
        {
            string result=string.Empty;
            HttpCookie cookie=HttpContext.Current.Request.Cookies[name];
            if (cookie!=null)
            {
                result=cookie.Value;
            }
            return result;
        }
        private static void SetCookieValue(string name,string value)
        {
            HttpCookie cookie=HttpContext.Current.Request.Cookies[name];
            if (cookie==null)
            {
                cookie=new HttpCookie(name);
            }
            cookie.Expires=DateTime.Now.AddYears(1);
            cookie.Value=value;
            HttpContext.Current.Response.Cookies.Add(cookie);
        }
    }
}